<template>
  <div class="app-container">
    <div class="query-container">
      <!-- 表单组件:ref:表单引用标识;绑定表单数据对象;动态计算标签宽度;行内排列方式为一行排列 -->
      <el-form
        ref="queryForm"
        :model="queryParams"
        :label-width="labelWidth"
        :inline="true"
      >
        <!-- 表单子组件:VueI18n国际化翻译标签文本;对应表单数据字段名 -->
        <el-form-item :label="$t('quoteType')" prop="quote_type">
          <!-- 下拉选择器:双向绑定类型值;占位符;回车键触发handleQuery查询方法 -->
          <el-select v-model="queryParams.quote_type" :placeholder="$t('inputquoteType')" @keyup.enter.native="handleQuery">
            <!-- 遍历选项数据源；唯一标识符；显示文本；实绩存储值 -->
            <el-option
              v-for="status in QuoteTypeOption"
              :key="status.value"
              :label="status.label"
              :value="status.value"
            >
              <span style="float: left">{{ status.label }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('quoteNo')" prop="quote_no">
          <el-input v-model="queryParams.quote_no" :placeholder="$t('inputquoteNo')" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item :label="$t('quoteContent')" prop="quote_content">
          <el-input v-model="queryParams.quote_content" :placeholder="$t('inputquoteContent')" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item :label="$t('quoteDate')" prop="quote_date">
          <el-date-picker v-model="queryParams.quote_date" type="date" value-format="yyyy-MM-dd" :placeholder="$t('inputquoteDate')" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('search') }}</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('reset') }}</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="tool-container">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">{{ $t('addBtn') }}</el-button>
        </el-col>
      </el-row>
    </div>
    <el-table-pro
      v-loading="loading"
      :highlight-current-row="true"
      :data="projectQuotaList"
      :columns-config="columnsConfig"
      @sort="sortChange"
    >
      <!-- 表格组件：国际化翻译列标题；居中显示；固定列宽220px；固定在表格右侧显示；自定义样式类 -->
      <el-table-column :label="$t('operate')" align="center" width="220" fixed="right" class-name="fixed-width">
        <!-- 获取当前行数据：slot-scope作用域插槽，用于访问子组件（）表格列传递的数据 -->
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetail(scope.row)">{{ $t('detailBtn') }}</el-button>
          <el-button v-auth="[]" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">{{ $t('modifyBtn') }}</el-button>
          <!-- 更多操作下拉菜单：trigger触发按钮点击（hover悬停/contextmenu右键点击/click点击）；下拉菜单事件点击菜单项时触发（commond：菜单项的指令标识） -->
          <el-dropdown v-more size="mini" trigger="click" @command="command => handleCommand(command, scope.row)">
            <!-- 下拉触发按钮 -->
            <span class="el-dropdown-link">
              <i class="el-icon-d-arrow-right el-icon--right" />{{ $t('moreBtn') }}
            </span>
            <!-- 下拉菜单选项：command="handleDelete"定义菜单项的唯一标识 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-auth="[]" command="handleDelete" icon="el-icon-delete">{{ $t('deleteBtn') }}</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table-pro>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.page_size"
      @pagination="getList"
    />
    <projectquota-sheet ref="projectquotaSheet" @refreshList="getList" />
    <projectquota-inquire ref="projectquotaInquire" />
  </div>
</template>

<script>
import { deleteProjectQutaApi } from '../api/projectquota.api'
import ElTablePro from '@/components/ElTablePro'
import listMixin from '@/mixins/ListMixin'
import { mapGetters } from 'vuex'
import ProjectquotaSheet from './projectquota-sheet.vue'
import ProjectquotaInquire from './projectquota-inquire.vue'
import { getCodeTableDetailApi } from '@/api/common/common'

export default {
  name: 'ProjectQuotaList',
  components: {
    ElTablePro,
    ProjectquotaSheet,
    ProjectquotaInquire
  },
  mixins: [listMixin],
  data() {
    return {
      QuoteTypeOption: [],
      queryParams: {
        'quote_no': undefined,
        'quote_content': undefined,
        'quote_date': undefined,
        'receive_date': undefined,
        'quote_type': undefined
      },
      actionFuncName: 'project/getProjectQuotaList',
      actionApi: {
        'delete': deleteProjectQutaApi
      }
    }
  },
  computed: {
    ...mapGetters(['projectQuotaList', 'name']),
    columnsConfig() {
      return [
        { prop: 'project_name', label: this.$t('projectPlanName'), width: 220 },
        { prop: 'quote_no', label: this.$t('quoteNo'), width: 100 },
        { prop: 'quote_type_desc', label: this.$t('quoteType'), width: 90 },
        { prop: 'quote_wfno', label: this.$t('quoteWFNo'), width: 100 },
        { prop: 'quote_content', label: this.$t('quoteContent'), width: 300 },
        { prop: 'quote_date', label: this.$t('quoteDate'), align: 'center', 'width': 110 },
        { prop: 'quote_amount', label: this.$t('quoteAmount'), align: 'right', 'width': 120 },
        { prop: 'quote_curr', label: this.$t('quoteCurrency'), 'width': 120 },
        { prop: 'standard_curr', label: this.$t('standardCurrency'), 'width': 120 },
        { prop: 'exchange_rate', label: this.$t('rate'), align: 'right', 'width': 120 },
        { prop: 'quote_days', label: this.$t('quoteDays'), align: 'right', 'width': 120 },
        { prop: 'receive_date', label: this.$t('receiveDate'), align: 'center', 'width': 110 },
        { prop: 'note', label: this.$t('quoteNote'), 'width': 220 },
        { prop: 'created', label: this.$t('createdUser'), 'width': 100 },
        { prop: 'created_date', label: this.$t('createdDate'), 'width': 160 },
        { prop: 'created_program', label: this.$t('createdProgram'), 'width': 200, 'show-overflow-tooltip': true },
        { prop: 'updated', label: this.$t('updatedUser'), 'width': 100 },
        { prop: 'updated_date', label: this.$t('updatedDate'), 'width': 160 },
        { prop: 'updated_program', label: this.$t('updatedProgram'), 'width': 200, 'show-overflow-tooltip': true }
      ]
    },
    labelWidth() {
      // 根据国际化设置确定标签宽度,如果语言环境是英语，则返回150px
      return this.$i18n.locale === 'en' ? '150px' : '80px';
    }
  },
  mounted() {
    // 获取Codetable下拉框数据
    getCodeTableDetailApi('ProjectQuotaModel', 'quote_type').then(resp => {
      this.QuoteTypeOption = resp.data;
    });
  },
  methods: {
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case 'handleDelete':
          this.handleDelete(row);
          break;
        default:
          break;
      }
    },
    /** 点击明细按钮 */
    handleDetail(row) {
      this.$refs.projectquotaInquire.openSheetDialog(row);
    },
    handleAdd() {
      this.$refs.projectquotaSheet.openSheetDialog()
    },
    handleUpdate(row) {
      this.$refs.projectquotaSheet.openSheetDialog({ ...row })
    },
    handleDelete(row) {
      const confirmMessage = this.$t('dataDeleteConfirm', { title: this.$t('quoteNo'), value: row.quote_no })
      const successMessage = this.$t('deleteSuccess', { title: this.$t('quoteNo'), value: row.quote_no })
      this.handleAction('delete', row.id, confirmMessage, successMessage)
    }
  }

}
</script>

  <style scoped>
  .el-input input, .el-select .el-input__inner {
      width: 220px;
      box-sizing: border-box;
  }
  </style>
